from reptile.workproject import WorkProject
from pyquery import PyQuery as pq


class Kxdaili(WorkProject):

	def work(self):
		super().work()
		for i in range(1, 3):
			for j in range(1, 5):
				page = self.scraper.send_request("http://www.kxdaili.com/dailiip/{}/{}.html".format(i, j))
				if page is None:
					continue
				for tr in pq(page)("table.active tr").items():
					data = [td.text() for td in tr.find("td").items()]
					if len(data) > 0:
						self.data.append(
							{"protocol": data[3].split(",")[0].lower(), "ip_port": "{}:{}".format(data[0], data[1]),
							 "country": data[5], "anonymity": True})
